
enum VER {
    //% block="V1"
    eV1,
    //% block="V2"
    eV2
}

//% color="#9f32f1" iconWidth=50 iconHeight=40
namespace gravitytts {


    //% block="TTS begin [VER]" blockType="command"
    //% VER.shadow="dropdown" VER.options="VER" VER.defl="VER.eV2"
    export function begin(parameter: any, block: any) {
        let ver = parameter.VER.code;
        Generator.addInclude("includeDFRobot_SpeechSynthesis","#include<DFRobot_SpeechSynthesis_M.h>");
        Generator.addObject("asrobject","DFRobot_SpeechSynthesis_I2C","sstts");

        Generator.addCode(`sstts.begin(sstts.${ver});`);
 
    }


    //% board="esp32,leonardo,mega2560,firebeetleesp32,telloesp32"
    //% block="TTS initialization [VER] [HS] mode RX (green): [RX] TX (blue): [TX]  " blockType="command" 
    //% HS.shadow="dropdown" HS.options="HS"
    //% RX.shadow="dropdown" RX.options="RX"
    //% TX.shadow="dropdown" TX.options="TX" 
    //% VER.shadow="dropdown" VER.options="VER" VER.defl="VER.eV1"
    export function DFRobot_tts_HsInit(parameter: any, block: any) {
        let ver = parameter.VER.code;
        let hs = parameter.HS.code;
        let rx = parameter.RX.code;
        let tx = parameter.TX.code;
        Generator.addInclude("includeDFRobot_SpeechSynthesis","#include<DFRobot_SpeechSynthesis_M.h>");
        Generator.addObject("asrobject","DFRobot_SpeechSynthesis_UART","sstts");
         

        if(Generator.board === 'esp32'){
            Generator.addCode(`${hs}.begin(115200,${rx},${tx});`);
        }
        else{
            Generator.addCode(`${hs}.begin(115200);`);
        }
        Generator.addCode(`sstts.begin(sstts.${ver},${hs}); `);
       
   }


    //% block="TTS speak [STR]" blockType="command"
    //% STR.shadow="string"  STR.defl="你好"   
    export function speak(parameter: any, block: any) {
        let str = parameter.STR.code;

        //if(str.substring(0,1)=="\"")  Generator.addCode(`sstts.speak(F(${str}));`);
        Generator.addCode(`sstts.speak(${str});`);
 
    }

    //% block="---"
    export function space2(){

    }

    //% block="F([STR])" blockType="reporter"
    //%STR.shadow="string"  STR.defl="你好"
    export function flashSTR(parameter: any, block: any) {
        let str = parameter.STR.code;

        Generator.addCode([`F(${str})`, Generator.ORDER_UNARY_POSTFIX]);
    }

    //% block="---"
    export function space1(){

    }  
    //% block="TTS set Voice[VOICE] Speed[SPEED] Tone[TONE] SoundType[SOUNDTYPE]" blockType="command"
    //% VOICE.shadow="range"  VOICE.params.min=0    VOICE.params.max=10    VOICE.defl=8
    //% SPEED.shadow="range"  SPEED.params.min=0    SPEED.params.max=10    SPEED.defl=5
    //% SOUNDTYPE.shadow="dropdown"  SOUNDTYPE.options="SOUNDTYPE"
    //% TONE.shadow="range"  TONE.params.min=0    TONE.params.max=10    TONE.defl=5
    export function setBase(parameter: any, block: any) {
        let voice = parameter.VOICE.code;
        let speed = parameter.SPEED.code;
        let type = parameter.SOUNDTYPE.code;
        let tone = parameter.TONE.code;


        Generator.addCode(`sstts.setVolume(${voice});`); 
        Generator.addCode(`sstts.setSpeed(${speed});`);
        Generator.addCode(`sstts.setSoundType(sstts.${type});`);
        Generator.addCode(`sstts.setTone(${tone});`);
 
 
    }


    //% block="TTS setEnglishPron [PRON]" blockType="command"
    //% PRON.shadow="dropdown"  PRON.options="PRON"  
    export function setEnglishPron(parameter: any, block: any) {
        let pron = parameter.PRON.code;


        Generator.addCode(`sstts.setEnglishPron(sstts.${pron});`);
 
    }


}
